package source.Objetos 
{
    import net.flashpunk.Entity;
    import net.flashpunk.graphics.Image;
    import net.flashpunk.graphics.Spritemap;
    import source.Assets;
    import source.Global;

	public class Detalle extends Entity {
		
		public var sprite:Spritemap;
		public var timerproxanim:int=numaleat(300, 1000);;
		public var spriteSeteado:Boolean = false;
		
		public function Detalle(x:int, y:int, _grafico:String, _nSprites:int = 0) {						
			super(x, y);
			if (_nSprites == 0)
				graphic = new Image(Assets[_grafico]);
			else {
				var	nFrames:Array = new Array();
				for (var i:Number = 0; i < _nSprites; i++)
					nFrames.push(i);
				
				sprite = new Spritemap(Assets[_grafico], Global.grid, Global.grid*_nSprites, animEnd);
				sprite.add("anim", nFrames, 0.3, false);
				graphic = sprite;
				spriteSeteado = true;
			}
		}
		
		override public function update():void
		{
			if (!timerproxanim && spriteSeteado) {
				sprite.play("anim", true);
				timerproxanim = numaleat(300, 1000);
			}
			timerproxanim--;
		}
		
		
		public function numaleat(min:int, max:int):int {
			return Math.floor(Math.random()*(max - min + 1)) + min;
		}
		
		public function animEnd():void { }
	}
}